package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 营销类型
 * @author Damon S.
 */
@Getter
@RequiredArgsConstructor
public enum MarketingType {
    /** 营销类型：未知，拼团，秒杀 */
    NA(0, "未知"),
    GROUPON(1, "拼团"),
    SPIKE(2, "秒杀");

    private final int code;
    private final String name;

    /**根据传值转换枚举值**/
    public static MarketingType parse(int code) {
        List<MarketingType> filteredStates =
                Arrays.stream(MarketingType.values())
                        .filter(state -> Objects.equals(state.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filteredStates) ? NA : filteredStates.get(0);
    }
}
